/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cv4j.app.slice;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.media.image.PixelMap;

import com.cv4j.app.ResourceTable;
import com.cv4j.app.app.BaseAbilitySlice;
import com.cv4j.app.utill.PixelMapUtil;
import com.cv4j.codeview.CodeDemo;
import com.cv4j.codeview.CodeView;
import com.cv4j.core.datamodel.CV4JImage;
import com.cv4j.core.filters.BaseFilter;
import com.cv4j.core.filters.BoxBlurFilter;
import com.cv4j.core.filters.CarveFilter;
import com.cv4j.core.filters.ColorFilter;
import com.cv4j.core.filters.CommonFilter;
import com.cv4j.core.filters.CompositeFilters;
import com.cv4j.core.filters.ConBriFilter;
import com.cv4j.core.filters.EmbossFilter;
import com.cv4j.core.filters.ExposureFilter;
import com.cv4j.core.filters.FloSteDitheringFilter;
import com.cv4j.core.filters.GammaFilter;
import com.cv4j.core.filters.GaussianBlurFilter;
import com.cv4j.core.filters.GaussianNoiseFilter;
import com.cv4j.core.filters.GlowFilter;
import com.cv4j.core.filters.MeansBinaryFilter;
import com.cv4j.core.filters.MosaicFilter;
import com.cv4j.core.filters.MotionFilter;
import com.cv4j.core.filters.NatureFilter;
import com.cv4j.core.filters.SepiaToneFilter;
import com.cv4j.core.filters.SinCityFilter;
import com.cv4j.core.filters.SpotlightFilter;
import com.cv4j.core.filters.VignetteFilter;
import com.cv4j.core.filters.WaterFilter;
import com.cv4j.core.filters.WhiteImageFilter;
import com.cv4j.rxcv4j.RxImageData;

/**
 * 显示多个滤镜效果
 *
 * @since 2021-05-20
 */
public class GridViewFilterAbilitySlice extends BaseAbilitySlice {
    private Image image1;
    private Image image2;
    private Image image3;
    private Image image4;
    private Image image5;

    private Image image6;
    private Image image7;
    private Image image8;
    private Image image9;
    private Image image10;

    private Image image11;
    private Image image12;
    private Image image13;
    private Image image14;
    private Image image15;

    private Image image16;
    private Image image17;
    private Image image18;
    private Image image19;
    private Image image20;
    private Image image21;
    private PixelMap mBitmap;

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_gridview_filter;
    }

    @Override
    protected void initComponents(Intent intent) {
        initView();
    }

    private void initView() {
        image1 = (Image) findComponentById(ResourceTable.Id_image1);
        image2 = (Image) findComponentById(ResourceTable.Id_image2);
        image3 = (Image) findComponentById(ResourceTable.Id_image3);
        image4 = (Image) findComponentById(ResourceTable.Id_image4);
        image5 = (Image) findComponentById(ResourceTable.Id_image5);

        image6 = (Image) findComponentById(ResourceTable.Id_image6);
        image7 = (Image) findComponentById(ResourceTable.Id_image7);
        image8 = (Image) findComponentById(ResourceTable.Id_image8);
        image9 = (Image) findComponentById(ResourceTable.Id_image9);
        image10 = (Image) findComponentById(ResourceTable.Id_image10);

        image11 = (Image) findComponentById(ResourceTable.Id_image11);
        image12 = (Image) findComponentById(ResourceTable.Id_image12);
        image13 = (Image) findComponentById(ResourceTable.Id_image13);
        image14 = (Image) findComponentById(ResourceTable.Id_image14);
        image15 = (Image) findComponentById(ResourceTable.Id_image15);

        image16 = (Image) findComponentById(ResourceTable.Id_image16);
        image17 = (Image) findComponentById(ResourceTable.Id_image17);
        image18 = (Image) findComponentById(ResourceTable.Id_image18);
        image19 = (Image) findComponentById(ResourceTable.Id_image19);
        image20 = (Image) findComponentById(ResourceTable.Id_image20);

        image21 = (Image) findComponentById(ResourceTable.Id_image21);

        image1.setPixelMap(ResourceTable.Media_test_mm);
        mBitmap = image1.getPixelMap();

        setPixMapImage(image2,new BoxBlurFilter());
        setPixMapImage(image3,new CarveFilter());
        setPixMapImage(image4,new ColorFilter());
        setPixMapImage(image5,new ConBriFilter());
        setPixMapImage(image6,new EmbossFilter());
        setPixMapImage(image7,new ExposureFilter());
        setPixMapImage(image8,new FloSteDitheringFilter());
        setPixMapImage(image9,new GammaFilter());
        setPixMapImage(image10,new GaussianBlurFilter());
        setPixMapImage(image11,new GaussianNoiseFilter());
        setPixMapImage(image12,new GlowFilter());
        setPixMapImage(image13,new MeansBinaryFilter());
        setPixMapImage(image14,new MosaicFilter());
        setPixMapImage(image15,new NatureFilter());
        setPixMapImage(image16,new SepiaToneFilter());
        setPixMapImage(image17,new SinCityFilter());
        setPixMapImage(image18,new SpotlightFilter());
        setPixMapImage(image19,new VignetteFilter());
        setPixMapImage(image20,new WaterFilter());
        setPixMapImage(image21,new WhiteImageFilter());
    }

    private void setPixMapImage(Image image, CommonFilter filter) {
        RxImageData.bitmap(mBitmap)
            .addFilter(filter)
            .into(image);
    }

}
